﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _14_using关键字用法以及在Dispose中的应用
{
    internal class Teacher : IDisposable
    {
        private bool disposed = false;

        private MemoryStream ms = new MemoryStream();

        public void Dispose()
        {
            Console.WriteLine("Teacher开始释放资源");
            Dispoing(true);
        }

        protected virtual void Dispoing(bool isDisposing)
        {
            if (!disposed)
            {
                if (isDisposing)
                {
                    ms.Dispose();
                    Console.WriteLine("Teacher的资源释放完成");
                }
                disposed = true;
            }
        }
        public void Show()
        {
            Console.WriteLine("Teacher类型运行");
        }
    }
}
